/*
 * 路由分发
 */
var router_config = {
    // "/api/base/achievement": require("./router/base/achievement"),
    // "/api/base/after_service": require("./router/base/after_service"),
    // "/api/base/class": require("./router/base/class"),
    // "/api/base/payment": require("./router/base/payment"),
    // "/api/base/staff": require("./router/base/staff"),
    // "/api/base/student": require("./router/base/student"),
    "/api/base/:tablename": require("./router/base/_base"),
    "/api/base/:tablename/:id": require("./router/base/_base"),

    // "/api/complex/roles": require("./router/complex/roles"),
    // "/api/complex/userlist": require("./router/complex/userlist"),
    "/api/complex/test": require("./router/complex/test"),
    "/api/complex/login": require("./router/complex/login"),
    "/api/complex/get_loginer": require("./router/complex/get_loginer"),
    "/api/complex/news": require("./router/complex/news"),
    "/api/complex/newsget": require("./router/complex/newsget"),
    "/api/complex/newschange": require("./router/complex/newschange"),
    "/api/complex/case": require("./router/complex/case"),
    "/api/complex/message": require("./router/complex/message"),
    "/api/complex/messageget": require("./router/complex/messageget"),
    "/api/complex/reply": require("./router/complex/reply"),
    // "/api/complex/:busname": require("./router/complex/_complex"),

    "/*": require("./router/static_files"),
}
var _router_error = function(req, res) {
    res.send(404,"404 no find.");
    console.error("----404----");
    console.log(req.route);
    console.error("----404----");
}
var router = function(app) {
    for (var i in router_config) {
        (function(router_key) {
            var router_object = router_config[router_key];
            console.log("路由器初始化配置接口：", router_key);
            app.all(router_key, function(req) {
                var router_foo = router_object[req.method.toLowerCase()] || _router_error;
                router_foo.apply(app, arguments);
            })
        }(i));
    }
}
module.exports = router;
